import { _decorator, Component, JsonAsset, Node } from 'cc';
import { DataTable } from '../Common/CommonInterface';
const { ccclass, property } = _decorator;

//统一管理，管理DataTable
@ccclass('DataBaseMgr')
export class DataBaseMgr {
    //数据，类型DataTable 
    protected _arrData:DataTable[] = [];    

    //当前数据索引，当前数据索引。
    protected _curIndex:number = 0;
    get curIndex(){
        return this._curIndex;
    }
    set curIndex(index:number){
        this._curIndex = index;
    }

    //通过json数据设置所有数据
    addData(jsonAsset:JsonAsset){
        this._arrData = <DataTable[]>jsonAsset.json;
    }
    //获取接口
    getDataByID<T extends DataTable>(id:number):T{
        for(let data of this._arrData){
            if(data.id == id){
                return <T>data;
            }
        }
        return null;
    }

    //通过索引
    getDataByIndex<T extends DataTable>(index:number):T{
        return <T>this._arrData[index];
    }

    //获取所有数据
    getAllDatas<T extends DataTable>():T[]{
        return <T[]>(this._arrData);
    }

    //获取当前数据
    getCurData<T extends DataTable>():T{
        return <T>this._arrData[this._curIndex];
    }

    //个数，几个数据
    getSize(){
        return this._arrData.length;
    }

}


// 具体游戏代码里：添加 LevelDtMgr EnemyDtMgr 都继承于这个

export class LevelDtMgr extends DataBaseMgr{
    
}

export class EnemyDtMgr extends DataBaseMgr{
    
}

export class PlayerDtMgr extends DataBaseMgr{
    
}

export class PropDtMgr extends DataBaseMgr{
    
}

export class PlayerSkillDtMgr extends DataBaseMgr{
    
}
export class EquipmentDtMgr extends DataBaseMgr{
    
}
export class ShiBingDtMgr extends DataBaseMgr{
    
}
export class EnemyShiBingDtMgr extends DataBaseMgr{
    
}

export class EnemyBossDtMgr extends DataBaseMgr{
    
}
export class PropertyDtMgr extends DataBaseMgr{

}


